﻿using Client.View;
using Client.View.CommonView;
using Client.View.MenuView;
using Client.View.OrgView;
using Client.View.UserView;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Client.Service
{
    /// <summary>
    /// Author: Leil
    /// Description: 主页面服务
    /// CreateTime: 2020/5/31 16:53:20
    /// </summary>
    public class ScreenService
    {
        private static ScreenService instance;
        private ScreenService()
        {
        }

        public static ScreenService Instance()
        {
            if (instance == null)
            {
                instance = new ScreenService();
            }
            return instance;
        }


        private Dictionary<string, UserControl> ScreenDic { get; set; } = new Dictionary<string, UserControl>();

        /// <summary>
        /// 根据页面code获取页面实例
        /// </summary>
        /// <param name="screenCode">页面code</param>
        /// <returns>对应的页面</returns>
        private UserControl GetScreenInstance(string screenCode)
        {
            switch (screenCode)
            {
                case "HOME_PAGE":
                    return new HomePage();
                case "USER_PAGE":
                    return new UserListPage();
                case "ROLE_PAGE":
                    return new RoleManagePage();
                case "MENU_PAGE":
                    return new MenuListPage();
                case "ORG_PAGE":
                    return new OrgListPage();
                default:
                    return null;
            }
        }

        /// <summary>
        /// 根据页面code获取页面对象
        /// </summary>
        /// <param name="screenCode">页面code</param>
        /// <returns></returns>
        public UserControl GetScreenPage(string screenCode)
        {
            if (ScreenDic.ContainsKey(screenCode))
            {
                return ScreenDic[screenCode];
            } else
            {
                UserControl page = GetScreenInstance(screenCode);
                if (page != null)
                {
                    ScreenDic.Add(screenCode, page);
                    return page;
                }
            }
            return null;
        }


        /// <summary>
        /// 是否初始化了页面
        /// </summary>
        /// <param name="screenCode">页面标识code</param>
        /// <returns>布尔值</returns>
        public bool HasInitScreenPage(string screenCode)
        {
            return ScreenDic.ContainsKey(screenCode);
        }


    }
}
